#ifndef FILEOPERATIONS_H
#define FILEOPERATIONS_H

#include <QObject>
#include <QFile>
#include <QDir>
#include <QUrl>
#include <QFileInfo>
#include <QString>
#include <QVariant>

class FileOperations : public QObject
{
    Q_OBJECT
public:
    explicit FileOperations(QObject *parent = nullptr);

    Q_INVOKABLE bool copyFileMulti(const QVariantList &sourcePaths, const QString &destinationPaths, bool outPut = true);
    Q_INVOKABLE bool copyFileV2(const QString &sourcePath, const QString &destinationPath, bool outPut = true);
    Q_INVOKABLE void cancelCopy(); // 用于取消传输


    Q_INVOKABLE bool copyFile(const QString &sourcePath, const QString &destinationPath);
    Q_INVOKABLE bool pathExists(const QString &path){
        QUrl url(path);
        QString filePath = url.toLocalFile();
        return QDir(filePath).exists();
    }
    Q_INVOKABLE QVariantList readFile(const QString &filePath);
    qint64 getFileSize(const QString &filePath);


signals:
    void multiCopyProgressUpdated(int filesCompleted, int totalFiles); //多文件 已完成和总数
    void allFilesSuccessfullyExported(int filesCompleted, int totalFiles);

    void copyProgressUpdated(qint64 bytesCopied, qint64 totalBytes); //当前字节 ，总字节


    void fileSuccessfullyExported();
    void fileFailExported();
    void updateFile(const QString &fileContent);

private:
    std::atomic<bool> cancelRequested;
    bool copyFileIner(const QString &sourcePath, const QString &destinationPath);
    bool copyDir(const QString &sourceDirPath, const QString &destinationDirPath);
};

#endif // FILEOPERATIONS_H
